﻿using CoreCms.Net.IServices;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.UI;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using NPOI.SS.Formula.Functions;
using System.ComponentModel;
using System.Threading.Tasks;

namespace CoreCms.Net.Web.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class updateapkController : ControllerBase
    {
        private readonly IWebHostEnvironment _webHostEnvironment;
        private readonly IupdateapkServices _updateapkServices;

        /// <summary>
        /// 构造函数
        ///</summary>
        public updateapkController(IWebHostEnvironment webHostEnvironment
            , IupdateapkServices updateapkServices
            )
        {
            _webHostEnvironment = webHostEnvironment;
            _updateapkServices = updateapkServices;
        }


        // POST: Api/updateapk/DoCreate
        /// <summary>
        /// 创建提交
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        [Description("创建提交")]
        public async Task<WebApiCallBack> DoCreate([FromBody] updateapk entity)
        {
            var jm = await _updateapkServices.InsertAsync(entity);
            return jm;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [Description("获取列表")]
        public async Task<WebApiCallBack> GetPageList()
        {
            var jm = new WebApiCallBack() { status = true};
            var list = await _updateapkServices.SqlQueryable("select * from   updateapk where VersionCode = (SELECT max(VersionCode)  FROM updateapk)");
            //返回数据
            jm.data = list.Count > 0 ? list[0] : null;
            jm.code = 0;
            jm.msg = "数据调用成功!";
            return jm;
        }

    }
}
